﻿using System;
using Tools.Extensions;

namespace DL.D_Start_Lite
{
    public readonly struct Key
    {
        private readonly float m_K1;
        private readonly float m_K2;

        public Key(float k1, float k2)
        {
            this.m_K2 = k2;
            this.m_K1 = k1;
        }

        public static bool operator<(Key lhs, Key rhs) =>
            lhs.m_K1 < rhs.m_K1 || lhs.m_K1.Approx(rhs.m_K1) && lhs.m_K2 < rhs.m_K2;

        public static bool operator>(Key lhs, Key rhs) =>
            lhs.m_K1 > rhs.m_K1 || lhs.m_K1.Approx(rhs.m_K1) && lhs.m_K2 > rhs.m_K2;

        public static bool operator ==(Key lhs, Key rhs) => lhs.m_K1.Approx(rhs.m_K1) && lhs.m_K2.Approx(rhs.m_K2);

        public static bool operator !=(Key lhs, Key rhs) => !(lhs == rhs);

        public override bool Equals(object obj) => obj is Key key && key == this;

        public override int GetHashCode() => HashCode.Combine(m_K1, m_K2);

        public override string ToString() => string.Format("({0},{1})", m_K1, m_K2);

    }
}